package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.domain.PageText;
import com.ruoyi.web.service.IPageTextService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 富文本框页面Controller
 * 
 * @author ruoyi
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/system/text")
public class PageTextController extends BaseController
{
    @Autowired
    private IPageTextService pageTextService;

    /**
     * 查询富文本框页面列表
     */
    @PreAuthorize("@ss.hasPermi('system:text:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageText pageText)
    {
        startPage();
        List<PageText> list = pageTextService.selectPageTextList(pageText);
        return getDataTable(list);
    }

    /**
     * 导出富文本框页面列表
     */
    @PreAuthorize("@ss.hasPermi('system:text:export')")
    @Log(title = "富文本框页面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageText pageText)
    {
        List<PageText> list = pageTextService.selectPageTextList(pageText);
        ExcelUtil<PageText> util = new ExcelUtil<PageText>(PageText.class);
        util.exportExcel(response, list, "富文本框页面数据");
    }

    /**
     * 获取富文本框页面详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:text:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pageTextService.selectPageTextById(id));
    }

    /**
     * 新增富文本框页面
     */
    @PreAuthorize("@ss.hasPermi('system:text:add')")
    @Log(title = "富文本框页面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageText pageText)
    {
        return toAjax(pageTextService.insertPageText(pageText));
    }

    /**
     * 修改富文本框页面
     */
    @PreAuthorize("@ss.hasPermi('system:text:edit')")
    @Log(title = "富文本框页面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageText pageText)
    {
        return toAjax(pageTextService.updatePageText(pageText));
    }

    /**
     * 删除富文本框页面
     */
    @PreAuthorize("@ss.hasPermi('system:text:remove')")
    @Log(title = "富文本框页面", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pageTextService.deletePageTextByIds(ids));
    }
}
